<?php
namespace app\controllers;

use app\models\order\Order;
use app\models\Queue;
use app\models\user\UserLevel;
use app\services\Chain;
use yii\helpers\ArrayHelper;

class DemoController extends Controller
{
    public function actionIndex()
    {
        return 'hello php';
    }

    public function actionDel()
    {
        $id = $this->get('id');

        Queue::deleteAll(['order_id' => $id]);

        $order = Order::findOne(['id' => $id]);

        $order->status = -99;

        return $order->save();
    }

    public function actionTeam()
    {
        $id = $this->get('id');

        $children = Chain::getChildrenAll($id);
        $children = ArrayHelper::getColumn($children, 'id');

        $ids = array_merge([$id], $children);

        // var_dump($ids);exit;

        $orders = Order::find()
            ->where(['user_id' => $ids])
            ->select(['id', 'status', 'user_id', 'is_extract'])
            ->asArray()
            ->all();

        var_dump($orders);
    }
}